

#include<assert.h>
typedef unsigned char lu_byte;
#define isdeadm(ow,m)	((m) & (ow))
#define lua_assert(c)           assert(c)
#define otherwhite(g)	((g)->currentwhite ^ WHITEBITS)
#define isdead(g,v)	isdeadm(otherwhite(g), (v)->marked)
#define cast(t, exp)	((t)(exp))
#define cast_u(o)	cast(union GCUnion *, (o))
#define LUA_TSTRING		4
#define BIT_ISCOLLECTABLE	(1 << 6)
#define ctb(t)			((t) | BIT_ISCOLLECTABLE)
#define makevariant(t,v)	((t) | ((v) << 4))
#define rawtt(o)	((o)->tt_)
#define novariant(t)	((t) & 0x0F)
#define ttype(o)	(novariant(rawtt(o)))
#define checktag(o,t)		(rawtt(o) == (t))
#define checktype(o,t)		(ttype(o) == (t))
#define val_(o)		((o)->value_)
#define settt_(o,t)	((o)->tt_=(t))
#define check_exp(c,e)		(lua_assert(c), (e))
#define lua_longassert(c)	((void)0)
#define iscollectable(o)	(rawtt(o) & BIT_ISCOLLECTABLE)
#define withvariant(t)	((t) & 0x3F)

#define cast_byte(i)	cast(lu_byte, (i))
#define resetbits(x,m)		((x) &= cast_byte(~(m)))
#define bitmask(b)		(1<<(b))

#define G_NEW		0	/* created in current cycle */
#define G_SURVIVAL	1	/* created in previous cycle */
#define G_OLD0		2	/* marked old by frw. barrier in this cycle */
#define G_OLD1		3	/* first full cycle as old */
#define G_OLD		4	/* really old object (not to be visited) */
#define G_TOUCHED1	5	/* old object touched this cycle */
#define G_TOUCHED2	6	/* old object touched in previous cycle */

#define AGEBITS		7  /* all age bits (111) */
#define WHITE0BIT	3  /* object is white (type 0) */
#define WHITE1BIT	4  /* object is white (type 1) */
#define BLACKBIT	5  /* object is black */
#define bit2mask(b1,b2)		(bitmask(b1) | bitmask(b2))
#define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)
#define maskcolors	(bitmask(BLACKBIT) | WHITEBITS)
#define set2gray(x)	resetbits(x->marked, maskcolors)

#define STRCACHE_N		53
#define STRCACHE_M		2
#define cast_int(i)	cast(int, (i))
#define setage(o,a)  ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a))
#define cast_int(i)	cast(int, (i))
#define ttypetag(o)	withvariant(rawtt(o))
#define gcvalue(o)	check_exp(iscollectable(o), val_(o).gc)
#define obj2gco(v)	check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
#define righttt(obj)		(ttypetag(obj) == gcvalue(obj)->tt)

#define MINSTRTABSIZE	128
#define checkliveness(L,obj) \
	((void)L, lua_longassert(!iscollectable(obj) || \
		(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))))

#define lmod(s,size) \
	(check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))

typedef union Value {
  struct GCObject *gc; // string这里只用到gc
} Value;
#define TValuefields	Value value_; lu_byte tt_
typedef struct TValue {
  TValuefields;
} TValue;